// pages/detail_board/index.js
const http = require('../../utils/http.js');
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: null,
    title: null,
    content: null,
    fujian:null
  },
    //转义方法
   escape2Html(str) {
      var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
      return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; }).replace('<section', '<div').replace('<img', '<img style="max-width:100%;height:auto" ');
    },
    async loadnews()  {
    //postReq(url, data, cb)
   
    let url = 'board/detail';
    let data = {
      id: this.data.id,

    }

    let res= await http.post(url,data)
    
    this.setData({
      title: res.tip.title,
      content: this.escape2Html(res.tip.content),
      input_date: res.tip.createTime,
      fujian: res.tip.fujian,


    });
    
     

     
  


  },//end of loadnews
  toattachment: function () {
    //查看附件
    wx.downloadFile({

      url: this.data.fujian,

      success: function (res) {

        var filePath = res.tempFilePath

        wx.openDocument({

          filePath: filePath,

          success: function (res) {

          

          }

        })

      }

    })

    

  },// end of toattachment
  toback: function () {
    //返回
    wx.navigateBack({
      delta: 1
    });

  },// end of toback
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id;

    this.setData({
      id: id,


    });
    //加载详情
    this.loadnews();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})